package com.stu.entity.permission;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.stu.entity.base.BaseEntity;

@Entity
@Table(name = "PERMISSION_ROLE")
public class PermissionRole extends BaseEntity 	 {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String cname;//角色名称
	private String description;//角色描述

	private List<PermissionAuth> auths = new ArrayList<PermissionAuth>();//拥有权限集合

	public PermissionRole() {

	}

	public PermissionRole(String uuid) {
		super(uuid);
	}

	public PermissionRole(String cname, String description, List<PermissionAuth> auths) {
		super();
		this.cname = cname;
		this.description = description;
		this.auths = auths;
	}

	public void setCname(String cname) {
		this.cname = cname;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setAuths(List<PermissionAuth> auths) {
		this.auths = auths;
	}
	@Column(name = "cname", length = 50)
	public String getCname() {
		return cname;
	}
	@Column(name = "description", length = 255)
	public String getDescription() {
		return description;
	}
	
	@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
	@JoinTable(name = "permission_user_auths", joinColumns = { @JoinColumn(name = "role_id", referencedColumnName = "uuid") }, inverseJoinColumns = { @JoinColumn(name = "auth_id", referencedColumnName = "uuid") })
	public List<PermissionAuth> getAuths() {
		return auths;
	}

}
